package com.ssm.sfzy.controller;

import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.CourseReply;
import com.ssm.sfzy.service.CourseReplyService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author jitwxs
 * @date 2024年04月01日 15:01
 */
@RestController
@CrossOrigin
@RequestMapping("/courseReply")
public class CourseReplyController {

    @Autowired
    private CourseReplyService courseReplyService;

    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageSize,
            CourseReply courseReply
    ){
        Map<String, Object> map = courseReplyService.findPage(pageNum, pageSize, courseReply);
        return Result.success(map);
    }

    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id){
        CourseReply courseReply = courseReplyService.findById(id);
        return Result.success(courseReply);
    }

    @PostMapping("/add")
    public Object add(@RequestBody CourseReply courseReply){
        courseReplyService.add(courseReply);
        return Result.success();
    }

    @PutMapping("/edit")
    public Object edit(@RequestBody CourseReply courseReply){
        courseReplyService.edit(courseReply);
        return Result.success();
    }

    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable Integer id){
        courseReplyService.remove(id);
        return Result.success();
    }

    @DeleteMapping("/removeBatch")
    public Object remove(Integer[] ids){
        courseReplyService.removeBatch(ids);
        return Result.success();
    }
}
